﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PatternWell.PAC.SL;
using PatternWell.PAC;

namespace $rootnamespace$
{
    //TODO:$safeitemname$ - Implement View Contract 
    //Implement view contract on this instance of the partial class
    
    public partial class $safeitemname$:IViewContract
    {
        #region Logging Helper

        /// <summary>
        /// Partial helper method that will capture an exception and make it avaliable for logging.
        /// </summary>
        /// <param name="exception">The source exception that has occured.</param>
        /// <param name="methodQualifiedName">The fully qualified name of the method where the exception was caught.</param>
        partial void LogContractError(System.Exception exception, string methodQualifiedName);

        #endregion

        #region View Initialization Logic

        /// <summary>
        /// Helper method that will run additional initialization logic after the view has already been created.
        /// </summary>
        public override void InitializeView()
        {
            try
            {
                //TODO:$safeitemname$ - InitializeView
                //Initialize all view contract items here;

                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                SetupView();
            }
            catch(System.Exception initializeError)
            {
                LogContractError(initializeError, "$rootnamespace$.$safeitemname$.InitializeView");
            }
        }

        /// <summary>
        /// Helper method that runs additional setup logic for the view that is not related to the view contract. 
        /// </summary>
        partial void SetupView();

        #endregion

        #region Detach View Logic 

        /// <summary>
        /// Helper method that will inform the view that it should detach event handlers and should reinitialize the view model.
        /// </summary>
        public override void DetachViewResources()
        {
            try
            {
                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                ResetView();

                //TODO:$safeitemname$ - DetachViewResources
                //Release and reinitialize the view model if one has been implemented
                //Release are reinitialize all properties and events on the view contract
            }
            catch (System.Exception detachError)
            {
                LogContractError(detachError, "$rootnamespace$.$safeitemname$.DetachViewResources");
            }

        }

        /// <summary>
        /// Helper method that runs additional detach logic for the view that is not related to the view contract.
        /// </summary>
        partial void ResetView();

        #endregion

        #region Release View Logic

        /// <summary>
        /// Virtual method that gets implemented by the contract to release all resources consumed by the hosting controller.
        /// </summary>
        protected override void ReleaseViewContract()
        {
            try
            {
                //Helper method will be executed if the partial method has been implemented. Otherwise it will be removed from the compile step.
                CleanupView();

                //TODO:$safeitemname$ - ReleaseViewContract
                //Dipose the view model if a view model was implemented
                //Dipose each property implemented in the view contract
                //Dipose each event implemented in the view contract

                //Calling the base release logic after all logic has been executed.
                base.ReleaseViewContract();
            }
            catch (System.Exception releaseError)
            {
                LogContractError(releaseError, "$rootnamespace$.$safeitemname$.ReleaseViewContract");
            }
        }

        /// <summary>
        /// Optional helper method that runs additional release logic for the view that is not directly related to the view contract.
        /// </summary>
        partial void CleanupView();

        #endregion

    }
}
